package com.steven.sample.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView.Adapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.steven.sample.R;
import com.steven.sample.bean.First;
import com.steven.sample.viewholder.FirstViewHolder;

import java.util.ArrayList;

/**
 * description: FirstAdapter
 * author: Steven Xiao
 * date: 2017/3/3
 */
public class FirstAdapter extends Adapter<FirstViewHolder> {
    private static final String TAG = FirstAdapter.class.getSimpleName();

    private Context mContext;
    private ArrayList<First> mList;
    private LayoutInflater mInflater;

    public FirstAdapter(Context mContext, ArrayList<First> mList) {
        this.mContext = mContext;
        this.mList = mList;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public FirstViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new FirstViewHolder(mInflater.inflate(R.layout.item_rv_first, parent, false));
    }

    @Override
    public void onBindViewHolder(FirstViewHolder holder, final int position) {
        holder.getTvContent.setText(mList.get(position).getContent());
        holder.getTvContent.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.e(TAG, "position = " + position);
            }
        });
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        return mList.isEmpty() ? 0 : mList.size();
    }
}
